// Tomato_Soup_Can_Counter ACW
// Joe Pardue June 27, 2009

#include "libACW001.h"

// Sensor level constants
#define NO_CAN 300
#define YES_CAN 600

// 0 if NO_CAN, 1 if YES_CAN
int yes = 0;
// Can count
int count = 0;

// variable for analog input value
int analogValue = 0;






int main(void)
{
	init();		// Initialize the private stuff
	setup();	// Setup the public stuff

	for(;;)
		loop();	// Call loop() forever

	return 0;	// You never get here

}



void setup()
{
  // begin the serial communication
  //Serial.begin(9600);		// TAW
  serialBegin(9600);
}

void loop()
{
  // read the analog input on pin 0
  analogValue = analogRead(0);
  
  // print prolog to value
  //Serial.print("ADC Reading: ");		// TAW
  //Serial.print(analogValue, DEC);		// TAW
  printf("ADC Reading: %d", analogValue);
  
  // If the analogInput is greater than YES_CAN
  // and yes is equal 0 set yes to 1.
  // If analogInput is less than NO_CAN
  // and yes is equal 1, set yes equal 0
  // and increment count.
  if ((analogValue > YES_CAN) & (yes == 0))
  {
    yes = 1;
    //Serial.print(" - YES_CAN");		// TAW
	printf(" - YES_CAN");
  }
   else if ((analogValue < NO_CAN) & (yes == 1))
   {
     yes = 0;
     //Serial.print(" - NO_CAN");		// TAW
	 printf(" - NO_CAN");
     count++;
   }
   
   // show the count
   //Serial.print(" count = ");			// TAW
   //Serial.print(count, DEC);			// TAW
   printf(" count = %d\n", count);
   
   // print a newline
   //Serial.println();					// TAW
   
   // delay 1 second before the next reading:
   delay(1000);
}
